import { View, Image } from "@tarojs/components";
import { Tab, Tabs } from "@antmjs/vantui";
import { useEffect, useState } from "react";
import Taro from "@tarojs/taro";

const Result = () => {
  //   const list = ["版权", "专利"];
  const [tab] = useState("1");
  const [zhuanli, setZhuanli] = useState([]);
  const [banquan, setBanquan] = useState([]);
  const [banquanjs, setBanquanjs] = useState([]);


  const getData = () => {
    Taro.showLoading({ title: "加载中" });
    Taro.cloud
      .callFunction({
        name: "logins",
        data: {
          $url: "getFileZhuanli"
        }
      })
      .then((res: any) => {
        console.log(res.result.data);
        setZhuanli(res.result.data);
        Taro.hideLoading()
      });
  };

  const getBanquan = () => {
    Taro.showLoading({ title: "加载中" });
    Taro.cloud
      .callFunction({
        name: "logins",
        data: {
          $url: "getFileBanquan"
        }
      })
      .then((res: any) => {
        console.log(res.result.data);
        setBanquan(res.result.data);
        Taro.hideLoading()
      });
  };

  const getBanquanjs = () => {
    Taro.showLoading({ title: "加载中" });
    Taro.cloud
      .callFunction({
        name: "logins",
        data: {
          $url: "getFileBanquanjs"
        }
      })
      .then((res: any) => {
        console.log(res.result.data);
        setBanquanjs(res.result.data);
        Taro.hideLoading()
      });
  };

  useEffect(() => {
    getData();
    getBanquan();
    getBanquanjs()
  }, []);

  return (
    <View className='index'>
      <Tabs sticky active={tab} ellipsis={false}>
        <Tab title='学生版权' name='1'>
          {banquan.length > 0 &&
            banquan.slice(1).map((item: any, i: any) => (
              <View key={i}>
                <Image
                  style={{ width: "100%", margin: "5px" }}
                  src={
                    "cloud://banjiu-0glooskma15eac2d.6261-banjiu-0glooskma15eac2d-1305931933/" +
                    item.Key
                  }
                ></Image>
              </View>
            ))}
        </Tab>
        <Tab title='教师版权' name='2'>
          {banquanjs.length > 0 &&
            banquanjs.slice(1).map((item: any, i: any) => (
              <View key={i}>
                <Image
                  style={{ width: "100%", margin: "5px" }}
                  src={
                    "cloud://banjiu-0glooskma15eac2d.6261-banjiu-0glooskma15eac2d-1305931933/" +
                    item.Key
                  }
                ></Image>
              </View>
            ))}
        </Tab>
        <Tab title='专利' name='3'>
          {zhuanli.length > 0 &&
            zhuanli.slice(1).map((item: any, i: any) => (
              <View key={i}>
                <Image
                  style={{ width: "100%", margin: "5px" }}
                  src={
                    "cloud://banjiu-0glooskma15eac2d.6261-banjiu-0glooskma15eac2d-1305931933/" +
                    item.Key
                  }
                ></Image>
              </View>
            ))}
        </Tab>
        {/* <Tab title='' name='3'>
          内容 3
        </Tab> */}
      </Tabs>
    </View>
  );
};

export default Result;
